package logic

import (
	"context"
	"project/weeksrv/service/mysql"

	"project/weeksrv/internal/svc"
	"project/weeksrv/weeksrv"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetOrderByOrderSnLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetOrderByOrderSnLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderByOrderSnLogic {
	return &GetOrderByOrderSnLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetOrderByOrderSnLogic) GetOrderByOrderSn(in *weeksrv.GetOrderByOrderSnReq) (*weeksrv.GetOrderByOrderSnRes, error) {
	// todo: add your logic here and delete this line
	res, err := mysql.GetOrderByOrderSn(in.OrderSn)
	if err != nil {
		return nil, err
	}
	return &weeksrv.GetOrderByOrderSnRes{
		Order: &weeksrv.Order{
			OrderSn:     res.OrderSn,
			TotalPrice:  float32(res.TotalPrice),
			OrderStatus: int32(res.OrderStatus),
		},
	}, nil
}
